package presentacion;

import integracion.DatabaseManager;
import integracion.TareaDAO;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class EliminarTarea extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet
{
	   static final long serialVersionUID = 1L;


		protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
		{
			doAll(request, response);
		}

		protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
		{
			doAll(request, response);
		}

		private void doAll(HttpServletRequest request, HttpServletResponse response) throws IOException
		{

			if(request.getParameter("accion").equals("EliminarTareas"))
			{
				int codigo = Integer.parseInt(request.getParameter("opciones"));

				try
				{
					TareaDAO dao = new TareaDAO(DatabaseManager.getConnection());
					dao.eliminarTareaId(codigo);

					if(dao.eliminarTareaId(codigo)==true)
					{
						response.sendRedirect("index.jsp?page=GestionarTareas/GestionarTareas");
						return;
					}
					else
					{
						response.sendRedirect("index.jsp?error=No se pudo eliminar");
						return;
					}
				}
				catch (SQLException e)
				{
					e.printStackTrace();
				}

			}


		}
	}